package com.dhh.sky.widget;

import com.dhh.sky.R;
import com.dhh.sky.activity.BasicActivity;
import com.dhh.sky.activity.CameraActivity;
import com.dhh.sky.activity.SongListActivity;
import com.dhh.sky.notepad.NotesList;
import com.dhh.sky.util.Constant;
import com.slidingmenu.lib.app.SlidingFragmentActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class SlideListFragment extends ListFragment {
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		return inflater.inflate(R.layout.slide_list, null);
	}
	
	private class MenuItem {
		public String tag;
		public int iconRes;
		public MenuItem(String tag, int iconRes) {
			this.tag = tag; 
			this.iconRes = iconRes;
		}
	}
	
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		MenuAdapter adapter = new MenuAdapter(getActivity());
		adapter.add(new MenuItem(this.getString(R.string.navigate_download), R.drawable.ic_download_save));
		adapter.add(new MenuItem(this.getString(R.string.navigate_music), R.drawable.ic_music_player));
		adapter.add(new MenuItem(this.getString(R.string.navigate_note), R.drawable.ic_notes));
		adapter.add(new MenuItem(this.getString(R.string.navigate_camera), R.drawable.ic_camera));
		adapter.add(new MenuItem(this.getString(R.string.navigate_logout), R.drawable.ic_logout));
		
		setListAdapter(adapter);		
	}
	
	@Override
	public void onListItemClick(ListView listView,View view, int position, long id){
		SlidingFragmentActivity activity = (SlidingFragmentActivity) this.getActivity();
		if(position == 0){
			Toast.makeText(activity, "Donload files", Toast.LENGTH_LONG).show();
		}else if(position == 1){
			Intent intent = new Intent(activity,SongListActivity.class);
			intent.putExtra(Constant.PARAM_LIST, true);
			activity.startActivity(intent);
		}else if(position == 2){
			Intent intent = new Intent(activity,NotesList.class);			
			activity.startActivity(intent);
		}else if(position == 3){
			Intent intent = new Intent(activity,CameraActivity.class);
			activity.startActivity(intent);
		}else if(position == 4){
			Toast.makeText(activity.getApplicationContext(), "Logout", Toast.LENGTH_LONG).show();
		}		
		activity.toggle();
		
	}
	
	public class MenuAdapter extends ArrayAdapter<MenuItem> {
		public MenuAdapter(Context context) {
			super(context, 0);
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			if (convertView == null) {
				convertView = LayoutInflater.from(getContext()).inflate(R.layout.slide_list_row, null);
			}
			ImageView icon = (ImageView) convertView.findViewById(R.id.row_icon);
			icon.setImageResource(getItem(position).iconRes);
			TextView title = (TextView) convertView.findViewById(R.id.row_title);
			title.setText(getItem(position).tag);

			return convertView;
		}

	}
}
